package org.chipu.jnids.gui;

import java.awt.EventQueue;
import java.io.File;
import java.io.IOException;
import javax.swing.JFrame;
import org.chipu.jnids.beans.Profile;
import org.chipu.jnids.sce.profile.StatType;
import org.chipu.jnids.sce.profile.Stats.Characteristic;
import org.chipu.shared.util.file.FileUtils;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

public final class ProfileDisplayer extends JFrame {
	public static void main(String[] args) throws IOException, Exception {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					ProfileDisplayer frame = new ProfileDisplayer();
					// Profile p = new Profile("profile_t", true);
					Profile p = Profile.decode(FileUtils.readTextFile(new File("encoded_profile_files.xml")));
					frame.setProfile(p);
					frame.pack();
					frame.setLocationRelativeTo(null);
					frame.setVisible(true);
					System.exit(0);
				} catch(Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public ProfileDisplayer() {/**/}

	public void setProfile(Profile p) {
		setTitle("Profile: " + p.getName());
		removeAll();
		JFreeChart chart = ProfileCharts.createChart(p, StatType.getStatType(StatType.Type.CONNECTIONS_IN),
			Characteristic.AVERAGE);
		// LegendTitle legend = new LegendTitle();
		// chart.addLegend(legend);
		add(new ChartPanel(chart));
	}

	// private class ChartPanel extends JPanel {
	// @Override
	// protected void paintComponent(Graphics g) {
	// super.paintComponent(g);
	// if (chart != null)
	// chart.draw((Graphics2D) g, getBounds());
	// }
	// }
}